<?php

namespace App\Admin\Controllers;

use App\mobilecard;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class MobileCardController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'App\mobilecard';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new mobilecard());

        $grid->filter(function($filter){

            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            // 在这里添加字段过滤器
            $filter->like('Mobile', '手机号');

        });

        $grid->column('Mobile', __('手机号'));
        $grid->column('Operator', __('运营商'));
        $grid->column('Belongs', __('所属人'));
        $grid->column('Subordinate', __('归属地'));
        $grid->column('Charges', __('资费'));
        $grid->column('CardStorage', __('卡收纳位置'));
        $grid->column('TelephoneBalance', __('话费余额'));
        $grid->column('Remarks', __('卡号备注'))->display(function($text) {
            return str_limit($text, 12, '...');
        });



        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(mobilecard::findOrFail($id));


        $show->field('Mobile', __('手机号'));
        $show->field('Operator', __('运营商'));
        $show->field('Belongs', __('所属人'));
        $show->field('Subordinate', __('归属地'));
        $show->field('Charges', __('资费'));
        $show->field('CardStorage', __('卡收纳位置'));
        $show->field('TelephoneBalance', __('话费余额'));
        $show->field('Remarks', __('卡号备注'));


        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new mobilecard());


        $form->mobile('Mobile', __('手机号'));
        $form->text('Operator', __('运营商'));
        $form->text('Belongs', __('所属人'));
        $form->text('Subordinate', __('归属地'));
        $form->text('Charges', __('资费'));
        $form->text('CardStorage', __('卡收纳位置'));
        $form->text('TelephoneBalance', __('话费余额'));
        $form->text('Remarks', __('卡号备注'));



        return $form;
    }
}
